VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form FrmSVThamGiaPT 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Sinh vien tham gia phong trao"
   ClientHeight    =   8085
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   12150
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   8085
   ScaleWidth      =   12150
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame 
      Caption         =   "Thong tin chi tiet"
      Height          =   2655
      Left            =   4200
      TabIndex        =   0
      Top             =   360
      Width           =   7815
      Begin VB.TextBox txtTenPT 
         Height          =   375
         Left            =   1560
         Locked          =   -1  'True
         TabIndex        =   10
         Top             =   1200
         Width           =   4095
      End
      Begin VB.CommandButton btnChonPT 
         Caption         =   "..."
         Height          =   375
         Left            =   5760
         TabIndex        =   9
         Top             =   1200
         Width           =   375
      End
      Begin VB.CommandButton btnChonSV 
         Caption         =   "..."
         Height          =   375
         Left            =   5760
         TabIndex        =   8
         Top             =   600
         Width           =   375
      End
      Begin VB.TextBox txtTenSV 
         Height          =   375
         Left            =   1560
         Locked          =   -1  'True
         TabIndex        =   4
         Top             =   600
         Width           =   4095
      End
      Begin VB.CommandButton btnNhapMoi 
         Caption         =   "Nhap moi"
         Height          =   375
         Left            =   840
         TabIndex        =   3
         Top             =   1920
         Width           =   1215
      End
      Begin VB.CommandButton btnThem 
         Caption         =   "Them"
         Height          =   375
         Left            =   3360
         TabIndex        =   2
         Top             =   1920
         Width           =   1215
      End
      Begin VB.CommandButton btnXoa 
         Caption         =   "Xoa"
         Height          =   375
         Left            =   4920
         TabIndex        =   1
         Top             =   1920
         Width           =   1215
      End
      Begin VB.Label Label1 
         Caption         =   "Phong trao"
         Height          =   255
         Left            =   360
         TabIndex        =   11
         Top             =   1320
         Width           =   975
      End
      Begin VB.Label lblStation 
         Caption         =   "Sinh vien"
         Height          =   255
         Left            =   360
         TabIndex        =   5
         Top             =   720
         Width           =   975
      End
   End
   Begin MSComctlLib.ListView lstvData 
      Height          =   7455
      Left            =   120
      TabIndex        =   6
      Top             =   480
      Width           =   3975
      _ExtentX        =   7011
      _ExtentY        =   13150
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      FullRowSelect   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      Appearance      =   1
      NumItems        =   0
   End
   Begin VB.Label Label 
      Caption         =   "Danh muc sinh vien tham gia phong trao"
      Height          =   255
      Index           =   0
      Left            =   240
      TabIndex        =   7
      Top             =   120
      Width           =   4095
   End
End
Attribute VB_Name = "FrmSVThamGiaPT"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private WithEvents formHSSV As FrmHSSV
Attribute formHSSV.VB_VarHelpID = -1
Private WithEvents formDiemPT As FrmDiemPhongTrao
Attribute formDiemPT.VB_VarHelpID = -1
Private m_sMaSV As String
Private m_sMaPT As String
Private m_objPhongTrao As clsPhongTrao
Private m_ObjADORst  As ADODB.Recordset

Private Sub btnChonPT_Click()
    Set formDiemPT = New FrmDiemPhongTrao
    formDiemPT.EnableBtnChon = True
    formDiemPT.Show 1, Me
End Sub

Private Sub btnChonSV_Click()
    Set formHSSV = New FrmHSSV
    formHSSV.EnableBtnChon = True
    formHSSV.Show 1, Me
End Sub

Private Sub ResetFields()
    m_sMaSV = ""
    txtTenSV.Text = ""
    m_sMaPT = ""
    txtTenPT.Text = ""
End Sub

Private Sub btnNhapMoi_Click()
    ResetFields
End Sub

Private Sub btnThem_Click()
    Dim objPhongTraoDto As clsPhongTrao
    Dim errText As String
    
    If Not ValidateInput(errText) Then
        MsgBox errText, vbCritical, "ThongBao"
        Exit Sub
    End If
    
    Set m_objPhongTrao = New clsPhongTrao
    Set objPhongTraoDto = New clsPhongTrao
    
    objPhongTraoDto.masv = Trim(m_sMaSV)
    objPhongTraoDto.mapt = Trim(m_sMaPT)
    
    If m_objPhongTrao.Insert(objPhongTraoDto) Then
        LoadData
        ResetFields
        MsgBox GetReport("Them", "ThanhCong"), vbInformation, "ThongBao"
    Else
        MsgBox GetReport("Them", "ThatBai"), vbCritical, "ThongBao"
    End If
End Sub

Private Sub LoadData()
    Dim i As Integer
    Dim vLstViewItem As ListItem
    
    Set m_objPhongTrao = New clsPhongTrao
    Set m_ObjADORst = m_objPhongTrao.SelectAll
    lstvData.ListItems.Clear
    i = 1
    
    Do While Not m_ObjADORst.EOF
        Set vLstViewItem = lstvData.ListItems.Add(i)
        vLstViewItem = m_ObjADORst!masv & "#" & m_ObjADORst!mapt
        vLstViewItem.SubItems(1) = m_ObjADORst!HoDem & " " & m_ObjADORst!tensv
        vLstViewItem.SubItems(2) = m_ObjADORst!tenpt
        m_ObjADORst.MoveNext
        i = i + 1
    Loop

End Sub

Private Sub btnXoa_Click()
    If Trim(m_sMaSV) = "" Or Trim(m_sMaPT) = "" Then Exit Sub
    
    Set m_objPhongTrao = New clsPhongTrao
     
    If MsgBox("Ban co chac chan muon xoa khong", vbInformation + vbOKCancel, "ThongBao") = vbOK Then
        If m_objPhongTrao.Delete(Trim(m_sMaSV), Trim(m_sMaPT)) Then
            LoadData
            ResetFields
            MsgBox GetReport("Xoa", "ThanhCong"), vbInformation, "ThongBao"
        Else
            MsgBox GetReport("Xoa", "ThatBai"), vbCritical, "ThongBao"
        End If
    End If
End Sub

Private Sub Form_Load()
    Init
    LoadData
    Call ClearSelection(lstvData)
End Sub

Public Sub Init()
    lstvData.ColumnHeaders.Clear
    lstvData.ColumnHeaders.Add , , "MaSV#MaPT", lstvData.Width / 3
    lstvData.ColumnHeaders.Add , , "Sinh vien", lstvData.Width / 3
    lstvData.ColumnHeaders.Add , , "Phong trao", lstvData.Width / 3
End Sub

Private Sub formHSSV_EVENTChooseItem(ByVal masv As String, ByVal tensv As String)
    m_sMaSV = masv
    txtTenSV.Text = tensv
End Sub

Private Sub formDiemPT_EVENTChooseItem(ByVal mapt As String, ByVal tenpt As String)
    m_sMaPT = mapt
    txtTenPT.Text = tenpt
End Sub

Public Function ValidateInput(ByRef errText As String) As Boolean
    ValidateInput = True
    If Trim(txtTenSV.Text) = "" Then
        errText = "Ban chua chon sinh vien"
        ValidateInput = False
        Exit Function
    End If
    If Trim(txtTenPT.Text) = "" Then
        errText = "Ban chua chon phong trao"
        ValidateInput = False
        Exit Function
    End If
End Function

Private Sub lstvData_ItemClick(ByVal item As MSComctlLib.ListItem)
    Dim msv_mpt() As String
    Dim msv As String
    Dim mpt As String
    
    msv_mpt = Split(item, "#")
    msv = msv_mpt(0)
    mpt = msv_mpt(1)
    Set m_ObjADORst = m_objPhongTrao.SelectByID(msv, mpt)
    If Not m_ObjADORst Is Nothing Then
        m_sMaSV = m_ObjADORst!masv
        m_sMaPT = m_ObjADORst!mapt
        txtTenSV.Text = m_ObjADORst!tensv
        txtTenPT.Text = m_ObjADORst!tenpt
    End If
End Sub

